home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / STRNTRAN.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  1KB  |  47 lines

  1. /*  File   : strntrans.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 2 June 1984
  4.     Defines: strntrans()
  5.  
  6.     strntrans(dst, src, len, from, to)
  7.     Moves characters from src to dst, translating characters in from[]
  8.     to the corresponding characters in to[], until either len characters
  9.     have been moved or a NUL has been moved.  If fewer than len characters
  10.     are moved, the remainder of dst will be filled with NULs, much like
  11.     strncpy and family.  No value is returned.
  12.  
  13.     Apology: in the previous distribution of this package, strntrans was
  14.     defined the way memtrans is now defined.  This is more consistent with
  15.     the general naming conventions.
  16. */
  17.  
  18. #include "strings.h"
  19. #include "_str2map.h"
  20.  
  21. #if    VaxAsm
  22.  
  23. void strntrans(dst, src, len, from, to)
  24.     _char_ *dst, *src, *from, *to;
  25.     int len;
  26.     {
  27.      _str2map(0, from, to);
  28.        asm("movtuc 20(ap),*8(ap),$0,__map_vec,20(ap),*4(ap)");
  29.        /* now pad the destination out with NUL characters */
  30.        asm("movc5 $0,*8(ap),$0,r4,(r5)");
  31.     }
  32.  
  33. #else  ~VaxAsm
  34.  
  35. void strntrans(dst, src, len, from, to)
  36.     register _char_ *dst, *src;
  37.     register int len;
  38.     _char_ *from, *to;
  39.     {
  40.        _str2map(0, from, to);
  41.        while (--len >= 0 && (*dst++ = _map_vec[*src++])) ;
  42.        while (--len >= 0) *dst++ = NUL;
  43.     }
  44.  
  45. #endif VaxAsm
  46.  
  47.